import { Component, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import CustomStore from 'devextreme/data/custom_store';
import { ${camelComponentName1 }Service } from '../${camelComponentName2 }.service';
<#if hasAssociateWidget>
import { QuestionSearchService } from '../../../basi_info_mana/pr_ques_search/search.service';
</#if>
import { DxDataGridComponent } from 'devextreme-angular';
declare var $: any;

@Component({
    selector: 'app-${componentName }',
    templateUrl: './${componentName }.component.html',
    styleUrls: ['./${componentName }.component.css'],
<#if hasAssociateWidget>
    providers: [${camelComponentName1 }Service, QuestionSearchService]
<#else>
    providers: [${camelComponentName1 }Service]
</#if>
})
export class ${camelComponentName1 }Component implements OnInit {
    <#if hasAssociateWidget>
    constructor(public ${camelComponentName2 }Service: ${camelComponentName1 }Service,public questionSearchService: QuestionSearchService,
    private router: Router, private route: ActivatedRoute) {
        // 公司联想控件
        this.makeAsyncDataSource();
        // 工厂联想控件
        this.makeAsyncDataSource_factory();
    <#else>
    constructor(public ${camelComponentName2 }Service: ${camelComponentName1 }Service, private router: Router, private route: ActivatedRoute) {
    </#if>
        // let param: any = this.route.queryParams.value;
        this.searchGridateDate();
    }
    searchModel = new 。();

    <#list columnEntitys as item>
        <#if item.excelRowData.hasArrayTemplate>
            ${item.excelRowData.fieldName }Status = ${item.excelRowData.arrayTemplateJSON }
        </#if>
    </#list>
    //选中的数据源
    selectedData: any = [];
    //查询主表Table变化
    selection(data: any) {
        this.selectedData = data.selectedRowKeys;
    }

    ngOnInit() {
        $('ul').on('mouseover', function () {
            $(this).addClass('hover')
        })
        $('ul').on('mouseout', function () {
            $(this).removeClass('hover')
        })
    }
    gridDataSource: any = {};

    searchGridateDate() {
        this.gridDataSource.store = new CustomStore({
            load: (loadOptions: any) => {
                var pageSize = loadOptions.take ? loadOptions.take : 50000;
                var pageIndex = loadOptions.skip ? loadOptions.skip == 0 ? 1 : loadOptions.skip / pageSize + 1 : 1;
                var condition = ParameterUtils.toString({
                    "pageIndex": pageIndex,
                    "pageSize": pageSize,
                    "filter": this.searchModel
                })
                let uri = "。。。。。";
                return this.${camelComponentName2 }Service.searchGridData(condition, uri);
            }
        });
    }
    // 查询条件start
    @ViewChild('mainGrid') mainGrid: DxDataGridComponent;
    visibleBoolean: boolean = true;
    tabControlVisibleBoolean() {
        this.visibleBoolean = !this.visibleBoolean;
    }
    exot() {
        this.visibleBoolean = !this.visibleBoolean;
    }
    search() {
        this.mainGrid.instance.refresh();
    }
    reset() {
    this.searchModel = new Zmm27tWzdpZydp011Management();
    <#if hasAssociateWidget>
        <#if associateWidgetName=="都有">
            // 清除工厂 公司名称
            this._gridBoxValue = [];
            this._gridBoxValue_factory = [];
        <#elseif associateWidgetName=="公司">
            this._gridBoxValue = [];
        <#elseif associateWidgetName=="公司">
            this._gridBoxValue_factory = [];
        </#if>
    </#if>
    }
    // 查询条件end
    <#if hasAssociateWidget>
        <#if associateWidgetName=="都有">
            // 公司选择框 start==================
            companyDataSource: any = [];
            treeBoxValue: string[];
            // 获取公司名称数据
            makeAsyncDataSource() {
                this.companyDataSource = new CustomStore({
                    loadMode: "raw",
                    key: "bukrs",
                        load: (loadOptions: any) => {
                    return this.questionSearchService.searchCompany(null);
                    }
                });
            };
            selectCompany(data: any) {
                let bukrsList = data.selectedRowKeys;
                this.searchModel.bukrsList = bukrsList;
            }
            // 公司名称选择框的反选
            _gridBoxValue: number[] = [];
            get gridBoxValue(): number[] {
                return this._gridBoxValue;
            }
            set gridBoxValue(value: number[]) {
                this._gridBoxValue = value || [];
            }
            // 公司选择框 end==================

            // 工厂选择框 start==================
            treeBoxValue_factory: string[];
            factoryDataSource: any = [];
            // 获取工厂名称数据
            makeAsyncDataSource_factory() {
                this.factoryDataSource = new CustomStore({
                    loadMode: "raw",
                    key: "werks",
                    load: (loadOptions: any) => {
                        return this.questionSearchService.searchFactory(null);
                    }
                });
            };
            selectFactory(data: any) {
                let factoryCodeList = data.selectedRowKeys;
                this.searchModel.factoryCodeList = factoryCodeList;
            }
            // 工厂名称选择框的反选
            _gridBoxValue_factory: number[] = [];
            get gridBoxValue_factory(): number[] {
                return this._gridBoxValue_factory;
            }
            set gridBoxValue_factory(value: number[]) {
                this._gridBoxValue_factory = value || [];
            }
            // 工厂选择框 end==================
        <#elseif associateWidgetName=="公司">
            // 公司选择框 start==================
            companyDataSource: any = [];
            treeBoxValue: string[];
            // 获取公司名称数据
            makeAsyncDataSource() {
                this.companyDataSource = new CustomStore({
                    loadMode: "raw",
                    key: "bukrs",
                    load: (loadOptions: any) => {
                        return this.questionSearchService.searchCompany(null);
                    }
                });
            };
            selectCompany(data: any) {
                let bukrsList = data.selectedRowKeys;
                this.searchModel.bukrsList = bukrsList;
            }
            // 公司名称选择框的反选
            _gridBoxValue: number[] = [];
            get gridBoxValue(): number[] {
                return this._gridBoxValue;
            }
            set gridBoxValue(value: number[]) {
                this._gridBoxValue = value || [];
            }
            // 公司选择框 end==================
        <#elseif associateWidgetName=="工厂">
            // 工厂选择框 start==================
            treeBoxValue_factory: string[];
            factoryDataSource: any = [];
            // 获取工厂名称数据
            makeAsyncDataSource_factory() {
                this.factoryDataSource = new CustomStore({
                    loadMode: "raw",
                    key: "werks",
                    load: (loadOptions: any) => {
                        return this.questionSearchService.searchFactory(null);
                    }
                });
            };
            selectFactory(data: any) {
            let factoryCodeList = data.selectedRowKeys;
                this.searchModel.factoryCodeList = factoryCodeList;
            }
            // 工厂名称选择框的反选
            _gridBoxValue_factory: number[] = [];
            get gridBoxValue_factory(): number[] {
                return this._gridBoxValue_factory;
            }
            set gridBoxValue_factory(value: number[]) {
                this._gridBoxValue_factory = value || [];
            }
            // 工厂选择框 end==================
        </#if>
    </#if>
}
